// 称砝码, 以底数为基准, 不停的累加

//第一行：n --- 砝码的种数(范围[1,10])
//第二行：m1 m2 m3 ... mn --- 每种砝码的重量(范围[1,2000])
//第三行：x1 x2 x3 .... xn --- 每种砝码对应的数量(范围[1,10])
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n;
let mArr = [];
let numArr = [];
rl.on("line", (line)=>{
    if(n === undefined) {
        n = Number(line.trim())
    } else if(mArr.length === 0) {
        mArr = line.trim().split(" ").map(Number)
    } else{
        numArr = line.trim().split(" ").map(Number)
        console.log(getResult(n, mArr, numArr))

        // clear
        n = undefined
        mArr.length = 1
        numArr.length = 1

    }

})

function getResult(n, mArr, numArr) {
    let result = new Set()
    result.add(0)
    for (let i = 0; i < mArr.length; i++) {
        let arr = Array.from(result)
        for (let j = 1; j <= numArr[i]; j++) {
            for (const weight of arr) {
                result.add(weight + mArr[i] * j)
            }
        }
    }
    return result.size
}